package repository

import (
	"bbs-web/internal/domain"
	"bbs-web/internal/repository/cache"
	"context"
)

type RankingRepository interface {
	ReplaceTopN(ctx context.Context, arts []domain.Article) error
	GetTopN(ctx context.Context) ([]domain.Article, error)
}

type onlyCacheRankinRepo struct {
	cache cache.RankinCache
}

func NewRankingRepository(cache cache.RankinCache) RankingRepository {
	return &onlyCacheRankinRepo{cache: cache}
}

func (o *onlyCacheRankinRepo) ReplaceTopN(ctx context.Context, arts []domain.Article) error {
	return o.cache.SetrankingRedisCache(ctx, arts)
}

func (o *onlyCacheRankinRepo) GetTopN(ctx context.Context) ([]domain.Article, error) {
	return o.cache.GetrankingRedisCache(ctx)
}
